home *** CD-ROM | disk | FTP | other *** search
/ Aminet 2 / Aminet AMIGA CDROM (1994)(Walnut Creek)[Feb 1994][W.O. 44790-1].iso / Aminet / util / edit / aux_emacs.lha / spawn.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-05-27  |  7.4 KB  |  245 lines

  1. /*
  2.  * The routines in this file are called to create a subjob running a command
  3.  * interpreter. This code is a big fat nothing on CP/M-86. You lose.
  4.  */
  5. #include        <stdio.h>
  6. #include        "ed.h"
  7.  
  8. #ifdef    AMIGA
  9. #define  NEW   1006
  10. #endif
  11.  
  12. #ifdef    VMS
  13. #define EFN     0                               /* Event flag.          */
  14.  
  15. #include        <ssdef.h>                       /* Random headers.      */
  16. #include        <stsdef.h>
  17. #include        <descrip.h>
  18. #include        <iodef.h>
  19.  
  20. extern  int     oldmode[];                      /* In "termio.c"        */
  21. extern  int     newmode[];                      /* In "termio.c"        */
  22. extern  short   iochan;                         /* In "termio.c"        */
  23. #endif
  24.  
  25. #if    MSDOS
  26. #include        <dos.h>
  27. #endif
  28.  
  29. #ifdef    V7
  30. #include        <signal.h>
  31. #endif
  32.  
  33. /*
  34.  * Create a subjob with a copy of the command intrepreter in it. When the
  35.  * command interpreter exits, mark the screen as garbage so that you do a full
  36.  * repaint. Bound to "C-C". The message at the start in VMS puts out a newline.
  37.  * Under some (unknown) condition, you don't get one free when DCL starts up.
  38.  */
  39. spawncli(f, n)
  40. {
  41. #ifdef    AMIGA
  42.         long newcli;
  43.     extern int Enable_Abort;
  44.  
  45.     Enable_Abort = 0;
  46.     if (IsInteractive(Input()) && IsInteractive(Output()))
  47.        {
  48.            newcli = Open("Aux:set/c:on/e:on/r:off", NEW);  /* reset paramters */
  49.            mlwrite("[Starting new CLI]\n");
  50.            sgarbf = TRUE;
  51.            Execute("", newcli, 0);
  52.            Close(newcli);
  53.        newcli = Open("Aux:set/e:off/c:off/r:on", NEW); 
  54.            Close(newcli);            /* Back to raw mode for editing */
  55.            }
  56.         else
  57.            {
  58.            newcli = Open("CON:0/0/639/199/MicroEmacs Subprocess", NEW);
  59.            mlwrite("[Starting new CLI]");
  60.            sgarbf = TRUE;
  61.            Execute("", newcli, 0);
  62.            Close(newcli);
  63.        }
  64.         return(TRUE);
  65. #endif
  66.  
  67. #ifdef    V7
  68.         register char *cp;
  69.         char    *getenv();
  70. #endif
  71. #ifdef    VMS
  72.         movecursor(term.t_nrow, 0);             /* In last line.        */
  73.         mlputs("[Starting DCL]\r\n");
  74.         (*term.t_flush)();                      /* Ignore "ttcol".      */
  75.         sgarbf = TRUE;
  76.         return (sys(NULL));                     /* NULL => DCL.         */
  77. #endif
  78. #ifdef    CPM
  79.         mlwrite("Not in CP/M-86");
  80. #endif
  81. #if    MSDOS
  82.         movecursor(term.t_nrow, 0);             /* Seek to last line.   */
  83.         (*term.t_flush)();
  84.         sys("\\command.com", "");               /* Run CLI.             */
  85.         sgarbf = TRUE;
  86.         return(TRUE);
  87. #endif
  88. #ifdef    V7
  89.         movecursor(term.t_nrow, 0);             /* Seek to last line.   */
  90.         (*term.t_flush)();
  91.         ttclose();                              /* stty to old settings */
  92.         if ((cp = getenv("SHELL")) != NULL && *cp != '\0')
  93.                 system(cp);
  94.         else
  95.                 system("exec /bin/sh");
  96.         sgarbf = TRUE;
  97.         sleep(2);
  98.         ttopen();
  99.         return(TRUE);
  100. #endif
  101. }
  102.  
  103. /*
  104.  * Run a one-liner in a subjob. When the command returns, wait for a single
  105.  * character to be typed, then mark the screen as garbage so a full repaint is
  106.  * done. Bound to "C-X !".
  107.  */
  108. spawn(f, n)
  109. {
  110.         register int    s;
  111.         char            line[NLINE];
  112. #ifdef    AMIGA
  113.         long newcli;
  114.     extern int Enable_Abort;
  115.  
  116.     Enable_Abort = 0;
  117.     if (IsInteractive(Input()) && IsInteractive(Output()))
  118.         {;}
  119.     else
  120.     {
  121.         if ((s=mlreply("CLI command: ", line, NLINE)) != TRUE)
  122.                 return (s);
  123.     newcli = Open("CON:1/1/639/199/MicroEmacs Subprocess", NEW);
  124.         Execute(line,0,newcli);
  125.         while ((*term.t_getchar)() != '\r')     /* Pause.               */
  126.                 ;
  127.         Close(newcli);
  128.         sgarbf = TRUE;
  129.     }
  130.         return(TRUE);
  131. #endif
  132. #ifdef    VMS
  133.         if ((s=mlreply("DCL command: ", line, NLINE)) != TRUE)
  134.                 return (s);
  135.         (*term.t_putchar)('\n');                /* Already have '\r'    */
  136.         (*term.t_flush)();
  137.         s = sys(line);                          /* Run the command.     */
  138.         mlputs("\r\n\n[End]");                  /* Pause.               */
  139.         (*term.t_flush)();
  140.         while ((*term.t_getchar)() != '\r')
  141.                 ;
  142.         sgarbf = TRUE;
  143.         return (s);
  144. #endif
  145. #ifdef    CPM
  146.         mlwrite("Not in CP/M-86");
  147.         return (FALSE);
  148. #endif
  149. #if    MSDOS
  150.         if ((s=mlreply("MS-DOS command: ", line, NLINE)) != TRUE)
  151.                 return (s);
  152.         system(line);
  153.         while ((*term.t_getchar)() != '\r')     /* Pause.               */
  154.                 ;
  155.         sgarbf = TRUE;
  156.         return (TRUE);
  157. #endif
  158. #ifdef    V7
  159.         if ((s=mlreply("! ", line, NLINE)) != TRUE)
  160.                 return (s);
  161.         (*term.t_putchar)('\n');                /* Already have '\r'    */
  162.         (*term.t_flush)();
  163.         ttclose();                              /* stty to old modes    */
  164.         system(line);
  165.         sleep(2);
  166.         ttopen();
  167.         mlputs("[End]");                        /* Pause.               */
  168.         (*term.t_flush)();
  169.         while ((s = (*term.t_getchar)()) != '\r' && s != ' ')
  170.                 ;
  171.         sgarbf = TRUE;
  172.         return (TRUE);
  173. #endif
  174. }
  175.  
  176. #ifdef    VMS
  177. /*
  178.  * Run a command. The "cmd" is a pointer to a command string, or NULL if you
  179.  * want to run a copy of DCL in the subjob (this is how the standard routine
  180.  * LIB$SPAWN works. You have to do wierd stuff with the terminal on the way in
  181.  * and the way out, because DCL does not want the channel to be in raw mode.
  182.  */
  183. sys(cmd)
  184. register char   *cmd;
  185. {
  186.         struct  dsc$descriptor  cdsc;
  187.         struct  dsc$descriptor  *cdscp;
  188.         long    status;
  189.         long    substatus;
  190.         long    iosb[2];
  191.  
  192.         status = SYS$QIOW(EFN, iochan, IO$_SETMODE, iosb, 0, 0,
  193.                           oldmode, sizeof(oldmode), 0, 0, 0, 0);
  194.         if (status!=SS$_NORMAL || (iosb[0]&0xFFFF)!=SS$_NORMAL)
  195.                 return (FALSE);
  196.         cdscp = NULL;                           /* Assume DCL.          */
  197.         if (cmd != NULL) {                      /* Build descriptor.    */
  198.                 cdsc.dsc$a_pointer = cmd;
  199.                 cdsc.dsc$w_length  = strlen(cmd);
  200.                 cdsc.dsc$b_dtype   = DSC$K_DTYPE_T;
  201.                 cdsc.dsc$b_class   = DSC$K_CLASS_S;
  202.                 cdscp = &cdsc;
  203.         }
  204.         status = LIB$SPAWN(cdscp, 0, 0, 0, 0, 0, &substatus, 0, 0, 0);
  205.         if (status != SS$_NORMAL)
  206.                 substatus = status;
  207.         status = SYS$QIOW(EFN, iochan, IO$_SETMODE, iosb, 0, 0,
  208.                           newmode, sizeof(newmode), 0, 0, 0, 0);
  209.         if (status!=SS$_NORMAL || (iosb[0]&0xFFFF)!=SS$_NORMAL)
  210.                 return (FALSE);
  211.         if ((substatus&STS$M_SUCCESS) == 0)     /* Command failed.      */
  212.                 return (FALSE);
  213.         return (TRUE);
  214. }
  215. #endif
  216.  
  217. #if    MSDOS
  218. /*
  219.  * This routine, once again by Bob McNamara, is a C translation of the "system"
  220.  * routine in the MWC-86 run time library. It differs from the "system" routine
  221.  * in that it does not unconditionally append the string ".exe" to the end of
  222.  * the command name. We needed to do this because we want to be able to spawn
  223.  * off "command.com". We really do not understand what it does, but if you don't
  224.  * do it exactly "malloc" starts doing very very strange things.
  225.  */
  226. sys(cmd, tail)
  227. char    *cmd;
  228. char    *tail;
  229. {
  230. #ifdef MWC86
  231.         register unsigned n;
  232.         extern   char     *__end;
  233.  
  234.         n = __end + 15;
  235.         n >>= 4;
  236.         n = ((n + dsreg() + 16) & 0xFFF0) + 16;
  237.         return(execall(cmd, tail, n));
  238. #endif
  239.  
  240. #ifdef LATTICE
  241.         return forklp(cmd, tail, NULL);
  242. #endif
  243. }
  244. #endif
  245.